﻿using System;

namespace OpenXml.IO.Packaging
{
    public class PackageRelationship
    {
        private static readonly Uri CONTAINER_RELATIONSHIP_PART_NAME = PackUriHelper.CreatePartUri(new Uri("/_rels/.rels", UriKind.Relative));
        private string _id;
        private Package _package;
        private string _relationshipType;
        private bool _saved;
        private PackagePart _source;
        private TargetMode _targetMode;
        private Uri _targetUri;

        internal PackageRelationship(Package package, PackagePart sourcePart, Uri targetUri, TargetMode targetMode, string relationshipType, string id)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }
            if (targetUri == null)
            {
                throw new ArgumentNullException("targetUri");
            }
            if (relationshipType == null)
            {
                throw new ArgumentNullException("relationshipType");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            this._package = package;
            this._source = sourcePart;
            this._targetUri = targetUri;
            this._relationshipType = relationshipType;
            this._targetMode = targetMode;
            this._id = id;
        }

        internal static Uri ContainerRelationshipPartName
        {
            get
            {
                return CONTAINER_RELATIONSHIP_PART_NAME;
            }
        }

        public string Id
        {
            get
            {
                return this._id;
            }
        }

        public Package Package
        {
            get
            {
                return this._package;
            }
        }

        public string RelationshipType
        {
            get
            {
                return this._relationshipType;
            }
        }

        internal bool Saved
        {
            get
            {
                return this._saved;
            }
            set
            {
                this._saved = value;
            }
        }

        public Uri SourceUri
        {
            get
            {
                if (this._source == null)
                {
                    return PackUriHelper.PackageRootUri;
                }
                return this._source.Uri;
            }
        }

        public TargetMode TargetMode
        {
            get
            {
                return this._targetMode;
            }
        }

        public Uri TargetUri
        {
            get
            {
                return this._targetUri;
            }
        }
    }
}


